/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.ui.container.collection
{
	import ua.kiev.gcore.ui.container.IUIItem;

	public class UIItemCollection
	{
		private var list:Vector.<IUIItem>;
		public function UIItemCollection()
		{
			list = new Vector.<IUIItem>();
		}
		
		public function get Length():int{
			return list.length;
		}
		
		public function pushItem(item:IUIItem):void{
			list.push(item);
		}
		
		public function removeItem(item:IUIItem):IUIItem{
			var result:IUIItem;			
			var index:int = getItemIndex(item);
			
			if(index > 0){
				result = list[index];				
				list.splice(index, 1);
			}
			
			return result;			
		}
		
		public function getItemIndex(item:IUIItem):int{
			var result:int = -1;
			var listItem:IUIItem;
			
			for (var i:int = 0; i < list.length; i++){
				listItem = list[i];
				
				if(listItem){
					if(listItem.id == item.id){
						result = i;
						break;
					}
				}
			}
			
			return result;
		}
	}
}